package edu.sctu.zhuyingzhi.month201506.day20150613.Serialize;

import java.io.*;
import java.text.MessageFormat;

/**
 * Created by Administrator on 2015/6/13.
 */
public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        serializablePerson();
        Person person = opSerializablePerson();
        System.out.println(person.getAge()+person.getName()+person.getAddress());
        System.out.println(MessageFormat.format("name={0},age={1}",person.getName(),person.getAge()));
    }

    private static void serializablePerson() throws IOException {
        Person person = new Person();
        person.setAge(18);
        person.setName("朱英志");
        person.setAddress("chengdu");
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File("D:/xulie.txt")));
        out.writeObject(person);
        System.out.println("序列化成功");
    }

    private static Person opSerializablePerson() throws IOException, ClassNotFoundException {
        ObjectInputStream opOut = new ObjectInputStream(new FileInputStream(new File("D:/xulie.txt")));
        Person person = (Person) opOut.readObject();
        System.out.println("反序列化成功");
        return person;
    }
}
